package fct.mpc.utils;

import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

	private static final int DATABASE_VERSION = 2;
	private static final String DATABASE_NAME = "SNIPE";
	
//	STATS TABLE
    public static final String STATS_TABLE_NAME = "user_stats";
    public static final String STATS_COLUMN_USER = "user";
    public static final String STATS_COLUMN_GAMES = "games_played";
    public static final String STATS_COLUMN_SNIPES = "snipes_hunted";
    public static final String STATS_COLUMN_BATTLES = "battles_fought";
    public static final String STATS_COLUMN_WINS = "battles_won";
    private static final String STATS_TABLE_CREATE =
                "CREATE TABLE " + STATS_TABLE_NAME + " (" +
        			STATS_COLUMN_USER + " TEXT," +
            		STATS_COLUMN_GAMES + " INTEGER DEFAULT 0, " +
            		STATS_COLUMN_SNIPES + " INTEGER DEFAULT 0, " +
            		STATS_COLUMN_BATTLES + " INTEGER DEFAULT 0, " +
            		STATS_COLUMN_WINS + " INTEGER DEFAULT 0);";
    
//  SNIPE TABLE
    public static final String SNIPE_TABLE_NAME = "snipes";
    public static final String SNIPE_COLUMN_ID = "_id";
    public static final String SNIPE_COLUMN_NAME = "name";
    public static final String SNIPE_COLUMN_ELEMENT = "element";
    public static final String SNIPE_COLUMN_HP = "health";
    public static final String SNIPE_COLUMN_ATTACK = "attack";
    public static final String SNIPE_COLUMN_DEFENSE = "defense";
    public static final String SNIPE_COLUMN_IMAGE = "image";
    public static final String SNIPE_COLUMN_USERHUNTED = "hunted";
    private static final String SNIPE_TABLE_CREATE = 
    		"CREATE TABLE " + SNIPE_TABLE_NAME + " (" +
    				SNIPE_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
    				SNIPE_COLUMN_NAME + " TEXT, " +
    				SNIPE_COLUMN_ELEMENT + " TEXT, " +
    				SNIPE_COLUMN_HP + " INTEGER DEFAULT 0," +
    				SNIPE_COLUMN_DEFENSE + " INTEGER DEFAULT 0," +
    				SNIPE_COLUMN_ATTACK  + " INTEGER DEFAULT 0," +
    				SNIPE_COLUMN_IMAGE + " TEXT, " +
    				SNIPE_COLUMN_USERHUNTED + " INTEGER DEFAULT 0);";

	

    public DatabaseHelper(Context context) {
    	super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL( STATS_TABLE_CREATE );
        db.execSQL( SNIPE_TABLE_CREATE );
        
        ContentValues updateValue = new ContentValues();
		updateValue.put( DatabaseHelper.STATS_COLUMN_USER, "user1" );
        
        db.insert(STATS_TABLE_NAME, STATS_COLUMN_USER, updateValue);
    }

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DatabaseHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + STATS_TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + SNIPE_TABLE_NAME);
		onCreate(db);
	}

	

}
